/*INCLUDES *******************************************************************/

#include "ses_timer.h"


/* DEFINES & MACROS **********************************************************/

#define TIMER2_INT_vect  			TIMER2_COMPA_vect
#define TIMER2_MODE_A			    (1<<WGM21)
#define TIMER2_MODE_B				(1<<CS22)
#define TIMER2_INT_MASK			    (1<<OCIE2A)
#define TIMER2_INT_FLAG         	0
#define TIMER2_CYC_FOR_1MILLISEC	250

/*FUNCTION DEFINITION ********************************************************/
static pTimerCallback callback = NULL;

void timer2_init(pTimerCallback cb) {
	TCCR2A |= TIMER2_MODE_A;
	TCCR2B |= TIMER2_MODE_B;
	TIMSK2 |= TIMER2_INT_MASK;
	OCR2A  = TIMER2_CYC_FOR_1MILLISEC;

	callback = cb;
}

ISR(TIMER2_INT_vect) {
	if(callback != NULL)callback();
}
